package com.example.ending_demo.servlet;

import com.example.ending_demo.model.Address;
import com.example.ending_demo.model.PageInfo;
import com.example.ending_demo.service.AddressService;

import java.io.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(urlPatterns = "/AddressListServlet")
public class AddressListServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.访问数据库读取通讯录列表数据
        AddressService addSvc = new AddressService();
        //userid也是从Session中获取
        ArrayList<Address> addrList = null;

        addrList = (ArrayList<Address>) addSvc.getAddressByUserID(1);


        //2.通过请求转发将通讯数据转发到address_list.jsp页面
        request.setAttribute("addressList",addrList);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/address_list.jsp");
        dispatcher.forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}